/*
 ============================================================================
 Name		: HelloS60AppView.cpp
 Author	  : qingbo.net
 Copyright   : Copy and paste anywhere you want
 Description : Application view implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "HelloS60AppView.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CHelloS60AppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CHelloS60AppView* CHelloS60AppView::NewL(const TRect& aRect)
	{
	CHelloS60AppView* self = CHelloS60AppView::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CHelloS60AppView* CHelloS60AppView::NewLC(const TRect& aRect)
	{
	CHelloS60AppView* self = new (ELeave) CHelloS60AppView;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHelloS60AppView::ConstructL(const TRect& aRect)
	{
	// Create a window for this application view
	CreateWindowL();
	
	iListBox = new (ELeave) CAknSingleNumberStyleListBox();
	iListBox->ConstructL(this, EAknListBoxSelectionList
			| EAknListBoxLoopScrolling);
	iListBox->SetContainerWindowL(*this);
	// Set scrollbars
	iListBox->CreateScrollBarFrameL(ETrue);
	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
			CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);

	// Create listbox item array
	iListBoxItems = new (ELeave) CDesCArrayFlat(4);
	// Create listbox items
	iListBoxItems->AppendL(_L("13\tLinux"));
	iListBoxItems->AppendL(_L("2\tSEM"));
	iListBoxItems->AppendL(_L("5\tSEO"));
	// Add items to listbox
	iListBox->Model()->SetItemTextArray(iListBoxItems);
	// Listbox deletes the item array
	iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
	iListBox->HandleItemAdditionL();
	
	// Activate Listbox
	iListBox->SetRect(Rect());
	iListBox->ActivateL();

	// Set the windows size
	SetRect(aRect);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::CHelloS60AppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CHelloS60AppView::CHelloS60AppView()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::~CHelloS60AppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CHelloS60AppView::~CHelloS60AppView()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CHelloS60AppView::Draw(const TRect& /*aRect*/) const
	{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();

	// Gets the control's extent
	TRect drawRect(Rect());

	// Clears the screen
	gc.Clear(drawRect);

	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CHelloS60AppView::SizeChanged()
	{
	iListBox->SetRect( Rect() );
	DrawNow();
	}

// -----------------------------------------------------------------------------
// CHelloS60AppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs, 
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CHelloS60AppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{

	// Call base class HandlePointerEventL()
	CCoeControl::HandlePointerEventL(aPointerEvent);
	}

TInt CHelloS60AppView::CountComponentControls() const
	{
	return (TInt) 1; // return nbr of controls inside this compound control
	}

CCoeControl* CHelloS60AppView::ComponentControl(TInt aIndex) const
	{
	switch (aIndex)
		{
		case 0:
			return iListBox;
		default:
			return NULL;
		}
	}

TKeyResponse CHelloS60AppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
	{
	TKeyResponse response = EKeyWasNotConsumed;
	//Check first that event type is EEventKey. It could be also
	//EEventKeyUp or EEventKeyDown which just inform that some key
	// is pressed or released.
	if (aType == EEventKey)
		{
		response = iListBox->OfferKeyEventL(aKeyEvent, aType);
		}
	// Return the key consumption status
	return response;

	}
// End of File
